package spring.cloud.consumer.movie.ribbon.user.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import spring.cloud.consumer.movie.ribbon.user.entity.User;

/**
 * Created by Enven on 2016/9/8.
 */
@Service("RibbonService")
public class RibbonService {
    //RestTemplate有点类似于一个WebService客户端请求的模版，可以调用http请求的WebService，并将结果转换成相应的对象类型.
    @Autowired
    private RestTemplate restTemplate;

    public User findById(Long id) {
        // http://服务提供者的serviceId/url
        return this.restTemplate.getForObject("http://spring-cloud-provider-user/"+id, User.class);
    }

}
